#include "graphics/gl/ooglutdisplaywindow.h"
#include "gl/glew.h"
#include <gl/glut.h>
#include "app/oogameapp.h"
#include "graphics/oorender.h"

//------------------------------------------------------------------------
ooGlutDisplayWindow::ooGlutDisplayWindow()
:m_width(800)
,m_height(600)
{
	// Do GLUT init
	int argc = 1;
	char* argv = "ooGlutDisplayWindow";
	glutInit(&argc,&argv);
	glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA);
	glutInitWindowSize(m_width, m_height);
	//glutInitWindowPosition(100, 100);
	glutCreateWindow(m_name.cString());
	//glutSetCursor(GLUT_CURSOR_NONE);
	glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
	glutDisplayFunc(&(ooGlutDisplayWindow::onWindowRender));
	glutWMCloseFunc(&(ooGlutDisplayWindow::onWindowClose));
}

//------------------------------------------------------------------------
ooGlutDisplayWindow::~ooGlutDisplayWindow()
{

}

//------------------------------------------------------------------------
void
ooGlutDisplayWindow::openWindow()
{
	//do nothing
}

//------------------------------------------------------------------------
void
ooGlutDisplayWindow::closeWindow()
{

}

//------------------------------------------------------------------------
void
ooGlutDisplayWindow::setName(const String& name)
{
	m_name = name;
}

//------------------------------------------------------------------------
const String&
ooGlutDisplayWindow::getName() const
{
	return m_name;
}

//------------------------------------------------------------------------
void
ooGlutDisplayWindow::setSize(int width, int height)
{
	dbbassert(width>0);
	dbbassert(height>0);
	m_width		= width;
	m_height	= height;
}

//------------------------------------------------------------------------
void
ooGlutDisplayWindow::tick(float elapsed)
{
	glutCheckLoop();
}

//------------------------------------------------------------------------
void 
ooGlutDisplayWindow::onWindowRender()
{

}

//------------------------------------------------------------------------
void 
ooGlutDisplayWindow::onWindowClose()
{
	ooGameApp::GetSingleton()->postQuitMessage();
}